﻿<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="com.ekingstar.framework.domain.Function"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="com.ekingstar.framework.service.*"%>
<%@page import="com.ekingstar.framework.domain.User"%>
<%@page import="com.ekingstar.framework.security.UserUtil"%>
<%
	User user = UserUtil.getCurrentUser();
	if (user == null){
		response.sendRedirect("../user/nologin.jsp");
	}
%>
<%@ include file="/common/include.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="<%=request.getContextPath()%>/css/css.css" rel="stylesheet" type="text/css" />

<style>
.LeftMenu_A_Title_on{cursor:pointer; text-indent:5px; font:12px/26px "宋体"; color:#0A4889;background:url("../images/nav_on.jpg") repeat-x; height:27px}
.LeftMenu_A_Title{cursor:pointer; text-indent:5px; font:12px/26px "宋体"; color:#0A4889;background:url("../images/nav_list.jpg") repeat-x; height:27px}
.menu_on{ color:#EE5C03;}
.LeftMenu_A_Content{display:none; text-indent:20px;}

.LeftLeaf_B_on{cursor:pointer;height:19px; text-indent:4px;padding-top:8px;color:#FB8615; background:url(../images/sub_on.jpg);border-bottom:1px solid #DCE9F4  }
.LeftLeaf_B{cursor:pointer;height:19px; text-indent:2px;padding-top:8px;border-bottom:1px solid #DCE9F4;padding-left:3px; padding-right:3px}

.LeftLeaf_C{cursor:pointer; background:#fff; border-bottom:1px solid #F1F1F1;height:19px; padding-top:8px;text-indent:30px}
.arrow{background:url(../images/arr0.jpg) no-repeat 0 2px; padding-left:15px;}
.sub_arrow{background:url(../images/list_ico.gif) no-repeat 0 5px; padding-left:10px;}
.sub_sub_arrow{background:url(../images/arr.gif) no-repeat 0 5px; padding-left:6px;}

</style>

<script language="javascript">
var menu_titles = [];
var menu_contents = [];
var menu_leafs = [];

window.onload = function ()
{
	var left_height = window.screen.availHeight-window.screenTop-49;	
	var menu_height = 400;

	var contents = document.getElementsByTagName( "div" );
	
	for(var i=0;i<contents.length;i++)
	{
		if(contents[i].className=="LeftMenu_A_Content")
		{
			menu_contents[menu_contents.length] = contents[i];
		}
		if(contents[i].className=="LeftMenu_A_Title")
		{
			menu_titles[menu_titles.length] = contents[i];
		}
		if(contents[i].className=="LeftLeaf_B")
		{
			menu_leafs[menu_leafs.length] = contents[i];
		}
	}
	
	menu_height = left_height - (27 * menu_contents.length)
	
	for(var j=0;j<menu_contents.length;j++)
	{
		if (j==0)
		{
			menu_contents[j].style.display = "block";
			menu_titles[j].className = "LeftMenu_A_Title_on";
		}

		menu_contents[j].style.height = menu_height;
	}
}

function ShowChildren(menuId,t)
{
	for(var i=0;i<menu_titles.length;i++)
	{
		var title = menu_titles[i];
		var content = menu_contents[i];
		
		if(content.id == 'LeftMenu_'+t+'_Content_'+menuId)
		{
			content.style.display = "block";
			title.className = "LeftMenu_A_Title_on";
		}
		else
		{
			content.style.display = "none";
			title.className = "LeftMenu_A_Title";
		}
	}
}

function ShowUri(menuId)
{
	for(var k=0;k<menu_leafs.length;k++)
	{
		var leaf = menu_leafs[k];
		
		if(leaf.id=="LeftLeaf_B_"+menuId)
		{
			leaf.className = "LeftLeaf_B_on";
		}
		else
		{
			leaf.className = "LeftLeaf_B";
		}
	}    
}
</script>
</head>
<body>
<div class="left" style="float:left; text-align:left;">
<% 
	String base = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath();
	Function parent = (Function)session.getAttribute("parent");
			
	WebApplicationContext context =  WebApplicationContextUtils.getWebApplicationContext(application);	
	IFunctionService fs = (IFunctionService) context.getBean("functionService");
	
	String userName = UserUtil.getCurrentUserId();
	
	if(parent!=null&&parent.getId()!=null){	
		List childen =parent.getChilden();
		if (childen != null){
			for(int a=0;a<childen.size();a++){//遍历parent的二级菜单List
				Function fun = (Function)childen.get(a);
				
				if(fun != null){
					out.println("<div id='LeftMenu_A_"+fun.getId()+"'>");
					List childenTemp =fun.getChilden();//三级菜单List
					if (childenTemp != null && !childenTemp.isEmpty()){	
						out.println("<div id='LeftMenu_A_Title_"+fun.getId()+"' class='LeftMenu_A_Title' onclick='javascript:ShowChildren(\""+fun.getId()+"\",\"A\");'><span class='arrow'>"+fun.getName()+"</span></div>");
					
						StringBuffer sbTree = new StringBuffer();					
						out.println("<div id='LeftMenu_A_Content_"+fun.getId()+"' class='LeftMenu_A_Content' style='width:100%;height:100%;overflow:auto;scrollbar-face-color: #DBEBFE; scrollbar-shadow-color: #B8D6FA; scrollbar-highlight-color: #FFFFFF; scrollbar-3dlight-color: #DBEBFE; scrollbar-darkshadow-color:#458CE4; scrollbar-track-color: #FFFFFF; scrollbar-arrow-color: #458CE4'>");						
							
							//sbTree.append("var rootNode_"+fun.getId()+" = new Ext.tree.TreeNode({text:'root'});\n");
							
							generateTree(sbTree,fun,childenTemp,userName,fs,base);						
														
							//sbTree.append("var tree_"+fun.getId()+ "= new Ext.tree.TreePanel({renderTo:'LeftMenu_A_Content_"+fun.getId()+"',root:rootNode_"+fun.getId()+",rootVisible:false,bodyStyle:'background-color:#E6F0F7',frame:false,lines:false,border:false});\n");
							//sbTree.append("tree_"+fun.getId()+".setRootNode(rootNode_"+fun.getId()+");\n");			
							//sbTree.append("tree_"+fun.getId()+".render('tree_"+fun.getId()+"');\n");	
											
							//out.println("<script>Ext.onReady(function(){"+sbTree+"});</script>");	
							out.print(sbTree);
						out.println("</div>");					
										
					}else {				
						String funshortname=fun.getName();
						if(funshortname!=null&&funshortname.length()>18)
							funshortname=funshortname.substring(0,18)+"...";	
							
						out.println("<div id='LeftMenu_A_Title_"+fun.getId()+"' class='LeftMenu_A_Title' onclick='javascript:ShowChildren(\""+fun.getId()+"\",\"A\");top.frames[\"main\"].location=\""+base+fun.getAddresss()+"\";'><span class='arrow'>"+funshortname+"</span></div>");
						out.println("<div id='LeftMenu_A_Content_"+fun.getId()+"' class='LeftMenu_A_Content'></div>");
																
					}
					out.println("</div>");
				}
				
			}//for
			
		}//if(parent.children!=null)
		
	}//if(parent!=null)
%>	
</div>
</body>

 </html> 
 
 <%!
	private static void generateTree(StringBuffer sbTree,Function parent,List children,String userName,IFunctionService fs,String base){
		if (children != null && children.size() > 0){
			for (int i = 0; i< children.size();i++){
				Function fun = (Function)children.get(i);
				if(fun.getShow().booleanValue()==false)//菜单设置为不显示
					continue;
				String url="#";
				if(fun.getAddresss()!=null&&fun.getAddresss().length()>2){
					url=base+fun.getAddresss();
				} 
								
				//sbTree.append("var rootNode_"+fun.getId()+" = new Ext.tree.TreeNode({text:'"+fun.getName()+"',qtip:'"+fun.getName()+"',href:'"+url+"',hrefTarget:'main'});\n");
				//sbTree.append("rootNode_"+parent.getId()+".appendChild(rootNode_"+fun.getId()+");\n");
				
				String funshortname=fun.getName();
				if(funshortname!=null&&funshortname.length()>18)
					funshortname=funshortname.substring(0,18)+"...";
				
				//sbTree.append("<div id='LeftLeaf_B_"+fun.getId()+"' class='LeftLeaf_B' onclick='javascript:ShowUri(\""+fun.getId()+"\");top.frames[\"main\"].location=\""+url+"\";'><span class='sub_sub_arrow'><a href='javascript:void(0)' title='"+fun.getName()+"'>"+funshortname+"</a></span></div>"+"\n");
				sbTree.append("<div id='LeftLeaf_B_"+fun.getId()+"' class='LeftLeaf_B' onclick='javascript:ShowUri(\""+fun.getId()+"\");window.location=\""+url+"\";'><span class='sub_sub_arrow'><a href='javascript:void(0)' title='"+fun.getName()+"'>"+funshortname+"</a></span></div>"+"\n");
				
				List childenTemp =fun.getChilden();
				if(childenTemp!= null && childenTemp.size() > 0){
					generateTree(sbTree,fun,childenTemp,userName,fs,base);
				} 
			}
		}
	}
%>